package com.sgb.jicai.view.adapter;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.entity.JiCaiCustomFieldBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import java.util.List;

/**
 * Time:2021/7/21
 * AUTHOR:F_Q
 * Description:
 */
public class JiCaiCustomFieldAdapter extends BaseRecycleAdapter<JiCaiCustomFieldBean> {

    private CustomFieldCallback customfields;

    public void setCustomfield(CustomFieldCallback customfield) {
        this.customfields = customfield;
    }

    public JiCaiCustomFieldAdapter(Context context, List<JiCaiCustomFieldBean> list) {
        super(context, R.layout.item_custom_field, list);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        RelativeLayout customFieldDeleta = holder.itemView.findViewById(R.id.custom_field_delete);//删除
        EditText custom_field_val = holder.itemView.findViewById(R.id.custom_field_val);//内容输入信息
        TextView edit_length = holder.itemView.findViewById(R.id.edit_length);//内容输入信息
        customFieldDeleta.setOnClickListener(v ->customfields.CustomFieldDeleta(position) );
        custom_field_val.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                edit_length.setText(s.toString().length()+"");
            }
        });

    }

    @Override
    public void convert(ItemViewHolder holder, JiCaiCustomFieldBean entity) {
        holder.setBinding(BR.viewModel, entity);
    }

    public interface CustomFieldCallback {
        void CustomFieldDeleta(int position);
    }
}
